package com.usian.controller;

import com.usian.Result;
import com.usian.feign.ItemFeign;
import com.usian.pojo.TbItem;
import com.usian.pojo.TbItemDesc;
import com.usian.pojo.TbItemParamItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("frontend/detail")
public class DetailController {

    @Autowired
    private ItemFeign itemFeign;

    /**
     * 获取商品主表详情
     *
     * @param itemId
     * @return
     */
    @RequestMapping("/selectItemInfo")
    public Result selectItemInfo(@RequestParam Long itemId){

        TbItem tbItem = itemFeign.selectItemInfo(itemId);
        if (tbItem!=null){
            return Result.ok(tbItem);
        }
        return Result.error("没有数据");
    }

    /**
     * 查询商品详情
     *
     * @param itemId
     * @return
     */
    @RequestMapping("/selectItemDescByItemId")
    public Result selectItemDescByItemId(@RequestParam Long itemId){

        TbItemDesc tbItemDesc = itemFeign.selectItemDescByItemId(itemId);
        if (tbItemDesc!=null){
            return Result.ok(tbItemDesc);
        }
        return Result.error("没有数据");
    }

    /**
     * 根据商品id查询商品规格参数
     *
     * @param itemId
     * @return
     */
    @RequestMapping("/selectTbItemParamItemByItemId")
    public Result selectTbItemParamItemByItemId(@RequestParam Long itemId){

        TbItemParamItem tbItemParamItem = itemFeign.selectTbItemParamItemByItemId(itemId);
        if (tbItemParamItem!=null){
            return Result.ok(tbItemParamItem);
        }
        return Result.error("没有数据");
    }
}
